﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Web;

namespace TalentDesk.Mvc.HelperClasses
{
    public static class EnumHelper
    {
        public static Dictionary<byte, string> GetEnumAsDictionary(Type enumtype)
        {
            Dictionary<byte, string> lst = new Dictionary<byte, string>();
            FieldInfo fi;
            DescriptionAttribute da;
            foreach (var enumValue in Enum.GetValues(enumtype))
            {
                fi = enumtype.GetField((enumValue.ToString()));
                da = (DescriptionAttribute)Attribute.GetCustomAttribute(fi,
                typeof(DescriptionAttribute));
                if (da != null)
                {
                    lst.Add(Convert.ToByte(enumValue), da.Description);
                }
            }
            return lst;
        }
        public static Dictionary<int, string> GetEnumAsDictionaryOfInt(Type enumtype)
        {
            Dictionary<int, string> lst = new Dictionary<int, string>();
            FieldInfo fi;
            DescriptionAttribute da;
            foreach (var enumValue in Enum.GetValues(enumtype))
            {
                fi = enumtype.GetField((enumValue.ToString()));
                da = (DescriptionAttribute)Attribute.GetCustomAttribute(fi,
                typeof(DescriptionAttribute));
                if (da != null)
                {
                    lst.Add(Convert.ToInt32(enumValue), da.Description);
                }
            }
            return lst;
        }
    }
}